package br.ufrj.neg.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.velocity.tools.view.VelocityViewServlet;

import br.ufrj.neg.preparacao.bean.NegociacaoBean;
import br.ufrj.neg.preparacao.model.NegociacaoModel;
import br.ufrj.neg.constants.General;

public class CarregarNegociacaoAction extends VelocityViewServlet {
	
	private static final long serialVersionUID = -3113158265371305805L;
	//private static Logger log = Logger.getLogger("rootLogger");
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {

			/*
			 * Pega a sessão
			 */
			HttpSession session = request.getSession(false);
			
			/*
			 * Pegando os parâmetros
			 */
			String idNegocio = General.getParameterUTF8(request,"idNegocio");

			/*
			 * Colocando o NegociacaoBean na sessão
			 */
			NegociacaoBean nb = new NegociacaoBean();
			NegociacaoModel nm = new NegociacaoModel();
			
			synchronized(session){
				nb = nm.getNegociacao(Integer.parseInt(idNegocio));
				session.setAttribute("NegociacaoBean", nb);
			}

			response.sendRedirect(General.APP_PATH + General.TEMPLATE_RISCO_PATH + "cadastraNegocio.vm");
	}
}
